E:/E+I/Informatik/Projekte/FH/n-Damen Problem/attack.c File Reference

#include "ndame.h"

Go to the source code of this file.

Functions

int attack (struct data *d1, int ii, int ik)
 attack


Detailed Description

PURPOSE: file contains the attack function

Author:
Daniel Hasemann
Version:
1.0
Date:
December 16th, 2005

Definition in file attack.c.


Function Documentation

int attack struct data d1,
int  ii,
int  ik
 

attack

This file gets the current position of the chessboard where calculate() wants to set a queen. It checks horizontally, vertically and diagonally whether there a queen. If there is a queen, the programme returns 1 else 0.

Parameters:
*d1 is a struct pointer
ii is an integer
ik is an integer
Returns:
1 or 0
See also:
calculate()
Author:
Daniel Hasemann
Date:
December 16th, 2005

Definition at line 25 of file attack.c.

References data::iboard.

Referenced by calculate().

00026 {
00027     int irow;
00028     int icol;
00029     
00030     irow=ii;                                          //reset board position
00031     icol=ik;                                          //reset board position
00032     
00033     for(irow;irow>=0;irow--)                          //lower
00034     {
00035         if(d1->iboard[irow][icol])
00036         {
00037             return 1;
00038         }
00039     }
00040     irow=ii;                                          //reset board position                                       
00041     
00042     while((irow>=0)&&(icol>=0))                       //left lower;
00043     {
00044         if(d1->iboard[irow][icol])
00045         {
00046             return 1;
00047         }
00048         
00049         irow--;
00050         icol--;
00051     }
00052     irow=ii;                                          //reset board position
00053     icol=ik;                                          //reset board position
00054     
00055     while((irow>=0)&&(icol<d1->iblength))             //right lower;
00056     {
00057         if(d1->iboard[irow][icol])
00058         {
00059             return 1;
00060         }
00061         
00062         irow--;
00063         icol++;
00064     }
00065     
00066     return 0;
00067 }


Generated on Sun Dec 18 19:26:14 2005 for n-Queens Problem by  doxygen 1.4.5